﻿using ITSM.Model.Entity;
using ITSM.Service;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace ITSM.Controllers.DemandLevel
{
    [Route("api/[controller]")]
    [ApiController]
    public class DemandLevelsController : ControllerBase
    {
        private readonly IDemand _demand;
        public DemandLevelsController(IDemand demand)
        {
            _demand = demand;
        }

        // GET: api/<DemandLevelsController>
        [HttpGet]
        public IActionResult Get()
        {
            return Ok(_demand.GetDemandLevels());
        }

        [HttpPut("/api/setLevelOrder")]
        public IActionResult SetLevelOrder(RYD_DemandList rYD_DemandList)
        {
            if (rYD_DemandList.RYD_DemandId == 0 || string.IsNullOrWhiteSpace(rYD_DemandList.RYD_ItId) || rYD_DemandList.RYD_Level==0)
            {
                return NotFound();
            }
            if (_demand.SetLevelOrder(rYD_DemandList))
            {
                return Ok(true);
            }
            return NotFound();
        }
    }
}
